home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 033a / icomblt5.zip / FGREP.DOC < prev    next >
Text File  |  1989-08-19  |  23KB  |  570 lines

  1.                                   FGREP 1.70
  2.                                   ----------
  3.  
  4.         "|" denotes changes in the recent versions.
  5.  
  6.  
  7.         Purpose
  8.         -------
  9.         FGREP (Fast GREP) is a small utility that can be used to find
  10.       | strings of characters in ASCII text files, and arbitrary
  11.       | sequences of bytes in other files.  String search capabilities
  12.         are not extensive (no regular expressions), but FGREP is small
  13.         and very, very fast.  FGREP is intended to replace DOS's FIND
  14.         filter with something faster and more flexible.
  15.  
  16.         UNIX people: we fully realize that this isn't the grep or fgrep
  17.         with which you are familiar.  We know that the RE in GREP means
  18.         "regular expressions" and we know that we don't support regular
  19.         expressions.  However, the name serves to point people in the
  20.         right direction.  Please don't write to tell us that this "isn't
  21.         really grep".
  22.  
  23.  
  24.         Syntax
  25.         ------
  26.         FGREP's syntax is
  27.  
  28.       |         FGREP [-abBceflmMopsvwx01] target {file}
  29.  
  30.         Looks complicated, lots of switches, but the most common use is
  31.         very simple:
  32.  
  33.                 FGREP hello myfile.txt
  34.  
  35.         This command would display all lines of MYFILE.TXT that contain
  36.         the string "hello".
  37.  
  38.  
  39.         Targets
  40.         -------
  41.         The target is what you're looking for in the file.  There are
  42.       | two ways to specify targets: as strings and as series of
  43.       | hexadecimal bytes.  The two can be combined in a single target
  44.       | specification.
  45.  
  46.         Strings are sequences of ASCII characters, like "hello".
  47.         Normally, you can just type in the string and forget it, but you
  48.         may have to "delimit" the string, i.e., bracket it by a pair of
  49.         matching non-alphanumeric characters (anything except - and $):
  50.  
  51.             'string'
  52.             /string/
  53.             .string.
  54.  
  55.         Choose a delimiter that does not appear in the string.  This is
  56.         no good:
  57.  
  58.             'you've made a mistake'
  59.  
  60.         Delimiters are required for a string target if any of these four
  61.         conditions are met:
  62.  
  63.       |     -- it is combined with hex byte sequences (more below)
  64.             -- it contains spaces or tabs
  65.             -- it begins with a non-alphanumeric character
  66.             -- it contains the DOS redirection characters < > |.
  67.  
  68.         In the last case, the string MUST be delimited by double quotes
  69.         ("), otherwise DOS will interpret it as redirection.
  70.  
  71.         Examples of valid string targets:
  72.  
  73.                 mov
  74.                 ax
  75.                 "two words"     (requires delimiter: contains a space)
  76.                 '/7'            (begins with non-alphanumeric)
  77.                 "f->x"          (contains ">", must use double quotes)
  78.  
  79.         It is always OK to delimit a string, even if delimiters are
  80.         unnecessary.
  81.  
  82.         REMEMBER that if the target contains DOS redirection characters
  83.         (<, >, or |), it MUST be delimited with double quotes ("") or
  84.         DOS will try to perform unwanted redirection.  For example:
  85.  
  86.             FGREP "a <= b" myfile.pas
  87.  
  88.       | Hex byte sequences are used for binary file searching when the
  89.       | bytes to be searched for are non-displayable characters or make
  90.       | no sense as strings (e.g., program code).  They are specified as
  91.       | pairs of hexadecimal bytes introduced by a leading '$':
  92.       |
  93.       |     $EF
  94.       |     $CD21           (CDh, 21h)
  95.       |     $CD$21          (identical; either format is OK)
  96.       |     $00FFFE00       (00h, FFh, FEh, 00h)
  97.       |     $CD 21          (ILLEGAL: no spaces permitted)
  98.       |
  99.       | You can combine strings and hex sequences by using a '+':
  100.       |
  101.       |     "abc"+$E74A+"def"
  102.  
  103.  
  104.         Target wildcards
  105.         ----------------
  106.         String targets (not hex targets) may contain one or mmore "?"
  107.         wildcards.  The ? will match any single non-null character in
  108.         the file.  E.g., "[?i]" will match "[si]", "[di]", etc., but not
  109.         "[i]".  Wildcards are not permitted when hex byte sequences are
  110.         used.
  111.  
  112.         If you want to search for the '?' character literally, use
  113.         '\?'.  For example, the target
  114.  
  115.                 what\?
  116.  
  117.         will search for the literal string "what?".
  118.  
  119.  
  120.         File list
  121.         ---------
  122.         You can list zero (see "Redirection"), one, or multiple files to
  123.         be searched.  Files listed may include DOS's * and ? wildcards.
  124.         Paths may be specified.  Examples:
  125.  
  126.             myfile.txt
  127.             *.txt
  128.             *.*
  129.             this.c that.c other.c
  130.             *.c *.pas
  131.             C:\UTIL\*.* D:\SYS\*.*
  132.             E:\LIBRARY\*.D?C
  133.  
  134.  
  135.         Redirection
  136.         -----------
  137.         If no file is listed, FGREP will take its input from the
  138.         standard input device, permitting redirection.  For example:
  139.  
  140.             DIR | fgrep pas
  141.  
  142.         would display any lines from a directory listing that contain
  143.         the string "pas".  Or,
  144.  
  145.             DIR | fgrep "<dir>"
  146.  
  147.         would list all subdirectories of the current directory.
  148.  
  149.         This command:
  150.  
  151.             arc p somefile foo.txt | FGREP somestring
  152.  
  153.         would display all lines from the file FOO.TXT in the archive
  154.         file SOMEFILE that contain "somestring".
  155.  
  156.       | FGREP will terminate with an error if no file is listed and
  157.       | standard input is not redirected.  Otherwise, it would be
  158.       | waiting for keyboard input to scan, possibly leading you to
  159.       | believe that it had hung up.
  160.  
  161.  
  162.         Examples of use
  163.         ---------------
  164.         Here are some examples of FGREP use:
  165.  
  166.         1. List all lines of MYFILE.TXT containing "hello"
  167.  
  168.             FGREP hello myfile.txt
  169.  
  170.         2. List all lines of all *.C files in the current directory that
  171.         contain "include foo.c":
  172.  
  173.             FGREP "include foo.c"  *.c
  174.  
  175.         3. List all lines from FILEA.EXT, FILEB.EXT, and FILEC.EXT that
  176.         contain the string "abcd" followed by any character:
  177.  
  178.             FGREP abcd? filea.ext fileb.ext filec.ext
  179.  
  180.       | 4. Display occurrences of the byte CDh followed by 21h (a DOS
  181.       | call) in the program MYPROG.EXE:
  182.       |
  183.       |     FGREP $CD21 myprog.exe
  184.       |
  185.       | 5. Display occurrences of the string "abc" followed by a byte of
  186.       | zeroes in all files in the C:\UTIL and D:\SYS:
  187.       |
  188.       |     FGREP 'abc' + $00 c:\util\*.* d:\sys\*.*
  189.  
  190.  
  191.         Output
  192.         ------
  193.         FGREP's default screen output looks like this:
  194.  
  195.                 **File <filename>
  196.                 [text of lines containing string]
  197.                 **File <filename>
  198.                 [text of lines containing string]
  199.  
  200.         If the "Microsoft" switch (-m or -M, see below) is used, the
  201.         output is in this format:
  202.  
  203.                 FILE.EXT(linenum): text
  204.  
  205.         This format is the standard format used by Microsoft (R)
  206.         language products and by its MEGREP.  If -m is used, only the
  207.         filename is displayed; if -M is used, the path will be included
  208.         if one was specified on the command line.
  209.  
  210.       | When a hex byte sequence or the -b switch is specified, FGREP
  211.       | uses the binary output mode.  See below for details.
  212.  
  213.         All useful output is sent to the standard output device, so it
  214.         may be piped to other programs or redirected to file:
  215.  
  216.                 FGREP target filea | yourprog
  217.                 FGREP target filea > test.txt
  218.  
  219.         Error messages and the program logo will appear always appear on
  220.         the console device, and will never appear in redirected or piped
  221.         output.
  222.  
  223.         FGREP returns an errorlevel to the operating system.  It will be
  224.         one of:
  225.  
  226.             0:   String not found in any file
  227.             1:   String found in at least one file
  228.             255: Error (file read error or bad parameter)
  229.  
  230.  
  231.         Switches
  232.         --------
  233.         These are the option switches that control how FGREP works.  All
  234.         switches are case-insensitive except -m/M and -b/B; for example,
  235.         either -a or -A will set ANSI mode.  All switches must precede
  236.         the target on the command line, but they may be in any order.
  237.         If you specify conflicting switches, the last one will be
  238.         effective.
  239.  
  240.         -a is ANSI mode.  If you have ANSI.SYS (or equivalent)
  241.            installed, escape characters (ASCII 27) in displayed text
  242.            lines can cause odd results.  If you use the -A switch,
  243.            FGREP will substitute an upside-down question mark (¿) for
  244.            ESC, possibly resulting in cleaner displays.  You'll only
  245.            need this switch if you have ANSI installed and there are ESC
  246.            characters in the files you're scanning.  Ignored in binary
  247.            mode.
  248.  
  249.       | -b specifies binary search mode/output.  This switch is
  250.       |    automatically set if you use a hex byte sequence in the
  251.       |    target.  See "binary search" below.
  252.       |
  253.       | -B specifies a case insensitive binary search.
  254.  
  255.         -c makes the search case sensitive ("String" will not match
  256.            "string" or "STRING").  Normally, FGREP ignores case.  This
  257.            switch is ignored in binary mode.
  258.  
  259.         -e specifies that ONLY an errorlevel is to be returned.
  260.            There will be no display at all.  This is equivalent to the
  261.            combination -s0.
  262.  
  263.         -f causes the "**File" header lines to be displayed only for
  264.            those files that contain the search string.
  265.  
  266.         -l adds line numbers to FGREP's output.  Ignored in binary mode.
  267.  
  268.         -m or -M specify Microsoft (R) output format.  See "Output"
  269.            above.  If -m is used, only the filename will appear.  If
  270.            -M is used, the path will be included if one was specified on
  271.            the command line.  Ignored in binary mode.
  272.  
  273.         -o specifies a maximum output width.  It should be followed by a
  274.            decimal number from 1 to 255.  For example, -o40 causes FGREP
  275.            to truncate all output to a maximum of 40 characters per
  276.            line.  Do not confuse the "O" (Output) switch with the "0"
  277.            (zero text) switch.  Ignored in binary mode.
  278.  
  279.         -p pauses on full screen of output.
  280.  
  281.         -s suppresses the "**File" header lines in the output.
  282.  
  283.         -v provides a reVerse or negative search.  That is, all lines
  284.            that do NOT contain the specified string are displayed.  This
  285.            provides a handy way to get rid of lines containing specified
  286.            text.  Suppose, for example, that you have a file containing
  287.            a list of file names, and you are interested in all files
  288.            EXCEPT those that contain a '$' in the name (perhaps they are
  289.            temporary files):
  290.  
  291.                 FGREP -v "$" filename
  292.  
  293.            This switch is ignored in binary mode.
  294.  
  295.         -w indicates that white space (blanks and tabs) is not
  296.            significant.  White space in both the search string and the
  297.            input file will be ignored.  If -w is specified, the wildcard
  298.            character (?) will match any nonblank character.  Ignored in
  299.            binary mode.
  300.  
  301.         -x Do not display the logo/copyright.
  302.  
  303.         -0 ("0" text lines) suppresses the display of lines of text
  304.            containing the specified string.  FGREP will skip immediately
  305.            to the next file when the string is found.  Do not confuse
  306.            this with the "O" (Output width) switch.
  307.  
  308.         -1 ("1" text line) specifies that only the first line containing
  309.            containing the specified string in each file will be
  310.            displayed.  FGREP will then skip immediately to the next
  311.            file.
  312.  
  313.  
  314.       | Binary search
  315.       | -------------
  316.       | If you use a hex byte sequence in your target, or if you specify
  317.       | the -b or -B switch, FGREP uses a "binary" mode rather than the
  318.       | usual text mode.  In this mode, FGREP is not concerned with
  319.       | "lines" of text and can be used to search any file for arbitrary
  320.       | sequences of strings.
  321.       |
  322.       | The output format is different.  Because there are no "lines" to
  323.       | display, FGREP shows the locations in the file where the target
  324.       | was found and the sixteen bytes surrounding the find (eight
  325.       | before, and eight after).  Here is the output format, split into
  326.       | two lines:
  327.       |
  328.       |     nnnnnnnn: n n n n n n n n . n n n n n n n n
  329.       |               cccccccc . cccccccc
  330.       |
  331.       | The initial sequence is the 32-bit file offset where the target
  332.       | was found, in hex.  For example,
  333.       |
  334.       |     0001C47A:
  335.       |
  336.       | indicates that the target was found at file offset 1C47A.
  337.       |
  338.       | The next two series (n n n ...) represent the eight bytes before
  339.       | and after the target (which, logically, occurred at the '.'
  340.       | position):
  341.       |
  342.       |     4B 7F 37 42 42 44 FF FF . 20 20 21 48 48 4F 3C 22
  343.       |
  344.       | The final series (ccc...) represents the same sixteen bytes
  345.       | displayed as characters.  Nondisplayable characters are shown as
  346.       | periods.
  347.       |
  348.       | Unlike text searches, binary searches are normally case
  349.       | sensitive.  That is, $41 ('A') will not match $61 ('a').  If you
  350.       | want a binary search to be case INsensitive ($41 matches both
  351.       | $41 and $61), use -B instead of -b.  The normal case sensitive
  352.       | switch (-c) is ignored.
  353.       |
  354.       | These switches are also ignored in binary mode:
  355.       |
  356.       |     -l          (show line numbers)
  357.       |     -w          (whitespace insensitive)
  358.       |     -v          (inverse search)
  359.       |     -m/M        (Microsoft format)
  360.       |
  361.       | Also, wildcards are not permitted in string targets when a
  362.       | binary search is used.
  363.  
  364.  
  365.         "Fast" search algorithm
  366.         -----------------------
  367.         FGREP uses two different search techniques.  Both are fast, but
  368.         one is faster than the other.  The "slow" search will be used
  369.         if any of these conditions are met:
  370.  
  371.             - line numbers or Microsoft (R) format used (-L or -m/M)
  372.             - the search is reVerse (-V)
  373.             - the search is whitespace insensitive (-W)
  374.             - the target string contains wildcards ("?")
  375.  
  376.         For other searches, the "fast" technique is typically 20-40%
  377.         faster than the "slow", although we've seen 70% improvements in
  378.         some cases.  One tester reported that FGREP located a string in
  379.         the last line of a 440K file in 0.97 seconds (IBM AT).
  380.  
  381.         The technique has its roots in searching for unusual (less
  382.         frequently used) characters, so it will make more of a
  383.         difference searching for "squeeze" (q is a little-used letter)
  384.         than it will searching for "eat".
  385.  
  386.  
  387.         Notes
  388.         -----
  389.         1. The -f and -s switches are mutually exclusive.  If both are
  390.         specified, the last one will be effective.
  391.  
  392.         2. The -M/m and -s switches are also mutually exclusive.
  393.  
  394.         3. If you specify the -e switch, FGREP will stop processing as
  395.         soon as a nonzero errorlevel is determined.  The -e switch is
  396.         really designed to enable other programs to determine whether or
  397.         not a specific file contains a specific string in as little time
  398.         as possible.  For example, here's an algorithm that will quickly
  399.         'touch' all files that do NOT contain a specified string:
  400.  
  401.                 for file in (*.*) do
  402.                     FGREP -e string file
  403.                     if errorlevel < 1 then touch file
  404.                 end
  405.  
  406.         4. The -s switch is automatically set when input is taken from
  407.         standard input.
  408.  
  409.         5. FGREP optimizes the combination -s0 (suppress headers, no
  410.         text) to a -e.
  411.  
  412.         6. If you just want to know which files contain a string, use -0;
  413.         it saves time because the rest of the file (after the first hit)
  414.         is skipped.  The combination -0f is particularly efficient
  415.         for this as it will simply display a list of files that contain
  416.         the string.
  417.  
  418.         7. If any of the -V, -W, -L, or -M switches are used, or if the
  419.         target contains wildcards, input lines are limited to a maximum
  420.         length of 500 characters (if you use a -w search, spaces don't
  421.         count).  FGREP expects standard text files; binary files will
  422.         yield weird results.  Word processor files may or may not work,
  423.         depending on how they are formatted.  Lines can be terminated by
  424.         any of CR, LF, or CR+LF.
  425.  
  426.         8. If output is redirected to disk, make sure there is enough
  427.         space available.  The program does not check.
  428.  
  429.  
  430.         A little note from the author
  431.         -----------------------------
  432.         I get lots of calls like this:
  433.  
  434.             I love FGREP because it's so fast.  It outperforms the next
  435.             faster text search utility I have by two-to-one.  If you
  436.             could just add (regular expressions | boolean searches), it
  437.             would be ideal.
  438.  
  439.         Well, one of the reasons why FGREP is so fast is because it
  440.         doesn't have to do lots of complex searching.  Because the
  441.         search is simple, I've been able to highly optimize the search
  442.         algorithms.  If I added regular expressions or boolean searches,
  443.         the main thing that distinguishes FGREP (its speed) from
  444.         other text search programs would go away.
  445.  
  446.         So.  I'm always glad to get comments and suggestions on FGREP,
  447.         so please keep calling and writing.  But I won't be adding
  448.         regular expressions or boolean searches.  If you need those,
  449.         there ae plenty of fancier search programs available (including
  450.         the real grep).  The penalty for greater flexibility is usually
  451.         less speed.
  452.  
  453.  
  454.         Version 1.70
  455.         ------------
  456.         Adds binary search.
  457.         Adds target concatenation (target+target)
  458.         Cancels if no file specified and not redirected.
  459.  
  460.         Version 1.64
  461.         ------------
  462.         Bug fix release only: fix garbage in -M display from 1.63
  463.  
  464.         Version 1.63
  465.         ------------
  466.         Distinguish between -M (path) and -m (no path) switches.
  467.         -M/-m and -S now mutually exclusive.
  468.         Allow search for literal '?' character via '\?'.
  469.  
  470.         Version 1.62
  471.         ------------
  472.         Added -M switch.
  473.         Increased max length of lines ("slow" search) from 256 to 500.
  474.  
  475.         Version 1.61
  476.         ------------
  477.         Fixed a problem with pausing on > 255 hits (-P not specified).
  478.  
  479.         Version 1.60
  480.         ------------
  481.         Added -P switch.
  482.         Fixed a problem with tab characters and -O switch.
  483.  
  484.         Version 1.59
  485.         ------------
  486.         Added -O switch.
  487.         Altered -L operations to allow for line numbers > 65535.  Line
  488.         numbers now right justified in a 6-character field.
  489.  
  490.         Version 1.58
  491.         ------------
  492.         Fixed two problems that were causing endless loops in 1.55-1.57.
  493.         Added -A switch.
  494.  
  495.         Version 1.57
  496.         ------------
  497.         Added -X switch.
  498.  
  499.         Versions 1.55/1.56
  500.         -----------------
  501.         "Fast" search algorithm added (thanks to Dave Angel for the
  502.         idea and the shove).
  503.  
  504.         Fixed problems with redirected input.
  505.  
  506.         Forced -v (reVerse) search to show blank lines.
  507.  
  508.         Versions 1.50/1.51
  509.         ------------------
  510.         These versions contain no new features but are significantly
  511.         faster than earlier versions.  Standard (case-insensitive)
  512.         searches run about 40% faster than 1.45 (which was 25-30%
  513.         faster than 1.40).  "Literal" searches (case-sensitive and
  514.         spacing-sensitive) are highly optimized and may be as much as
  515.         70% faster than 1.45.
  516.  
  517.         Version 1.45
  518.         ------------
  519.         We found a few areas that could be made more efficient.  This
  520.         version can be as much as 25-30% faster than version 1.40.
  521.  
  522.         The -L (line numbers) option was added, and improvements made to
  523.         parameter parsing such that delimiters are not always necessary.
  524.  
  525.  
  526.         Copyright/License/Warranty
  527.         --------------------------
  528.         This document and the program file FGREP.COM ("the software")
  529.         are copyrighted by the author.  The copyright owner hereby
  530.         licenses you to: use the software; make as many copies of the
  531.         program and documentation as you wish; give such copies to
  532.         anyone; and distribute the software and documentation via
  533.         electronic means.  There is no charge for any of the above.
  534.  
  535.         However, you are specifically prohibited from charging, or
  536.         requesting donations, for any such copies, however made; and
  537.         from distributing the software and/or documentation with
  538.         commercial products without prior permission.  An exception is
  539.         granted to not-for-profit user's groups, which are authorized to
  540.         charge a small fee (not to exceed $7) for materials, handling,
  541.         postage, and general overhead.  NO FOR-PROFIT ORGANIZATION IS
  542.         AUTHORIZED TO CHARGE ANY AMOUNT FOR DISTRIBUTION OF COPIES OF
  543.         THE SOFTWARE OR DOCUMENTATION, OR TO INCLUDE COPIES OF THE
  544.         SOFTWARE OR DOCUMENTATION WITH SALES OF THEIR OWN PRODUCTS.
  545.  
  546.         THIS INCLUDES A SPECIFIC PROHIBITION AGAINST FOR-PROFIT
  547.         ORGANIZATIONS DISTRIBUTING THE SOFTWARE, EITHER ALONE OR WITH
  548.         OTHER SOFTWARE, AND CHARGING A "HANDLING" OR "MATERIALS" FEE OR
  549.         ANY OTHER SUCH FEE FOR THE DISTRIBUTION.  NO FOR-PROFIT
  550.         ORGANIZATION IS AUTHORIZED TO INCLUDE THE SOFTWARE ON ANY MEDIA
  551.         FOR WHICH MONEY IS CHARGED.  PERIOD.
  552.  
  553.         No copy of the software may be distributed or given away without
  554.         this document; and this notice must not be removed.
  555.  
  556.         There is no warranty of any kind, and the copyright owner is not
  557.         liable for damages of any kind.  By using this free software,
  558.         you agree to this.
  559.  
  560.         The software and documentation are:
  561.  
  562.                            Copyright (C) 1985-1989 by
  563.                              Christopher J. Dunford
  564.                             The Cove Software Group
  565.                                  P.O. Box 1072
  566.                             Columbia, Maryland 21044
  567.  
  568.                                  (301) 992-9371
  569.                          CompuServe 76703,2002 [IBMNET]
  570.